package cc.rboot.masking.processor;

import cc.rboot.masking.core.IDataMaskingProcessor;
import org.springframework.util.StringUtils;

public class IDNumberMaskingProcessor implements IDataMaskingProcessor<String> {

    @Override
    public String masking(String idNumber, String condition) {
        if (!StringUtils.hasText(idNumber)) {
            if (idNumber.length() == 15){
                idNumber = idNumber.replaceAll("(\\w{6})\\w*(\\w{3})", "$1******$2");
            }
            if (idNumber.length() == 18){
                idNumber = idNumber.replaceAll("(\\w{6})\\w*(\\w{3})", "$1*********$2");
            }
        }
        return idNumber;
    }
}
